<template>
	<view class="fui-wrap">
		<fui-form error-position="1" labelColor="#7a7a7a" ref="form" top="0" :model="formData">
			<fui-form-item label="支付单号" prop="out_trade_no">
				<fui-input readonly :borderBottom="false" :padding="[0]" v-model="pay.out_trade_no"></fui-input>
			</fui-form-item>
			<fui-form-item label="订单详情">
				<fui-input readonly :borderBottom="false" :padding="[0]" v-model="pay.detail"></fui-input>
			</fui-form-item>
			<fui-form-item label="订单金额">
				<fui-input readonly :borderBottom="false" :padding="[0]" :value="parseNumber(pay.pay_price)">
					<text>元</text>
				</fui-input>
			</fui-form-item>
			<fui-form-item asterisk label="退款金额">
				<fui-input type="digit" :borderBottom="false" :padding="[0]" v-model="formData.refund_price">
					<text>元</text>
				</fui-input>
			</fui-form-item>
			<fui-form-item asterisk label="退款原因">
				<fui-input :borderBottom="false" :padding="[0]" v-model="formData.refund_cause"></fui-input>
			</fui-form-item>
			<view class="fui-btn__box">
				<fui-button :disabled="disabledButton" text="提交" bold @click="submit"></fui-button>
			</view>
		</fui-form>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {parseNumber} from '@/utils/util.js'
	export default {
		data() {
			return {
				pay:'',
				formData:{
					pay_id:'',
					refund_price:'',
					refund_cause:''
				},
				disabledButton:false
			}
		},
		onLoad(e) {
			this.pay=uni.getStorageSync('pay_detail');
			this.formData.pay_id=this.pay.id;
			this.formData.refund_price=parseNumber(this.pay.pay_price-this.pay.refund_price);
			uni.setStorageSync('pay_detail','');
		},
		methods: {
			...methods,
			parseNumber,
			submit:function(){
				if(!this.formData.refund_price){
					this.$msg('请输入退款金额');
					return;
				}
				if(!this.formData.refund_cause){
					this.$msg('请输入退款原因');
					return;
				}
				let can_price=parseNumber(this.pay.pay_price-this.pay.refund_price);
				if(this.formData.refund_price>can_price){
					this.$msg('最多只能退'+can_price+'元');
					return;
				}
				this.disabledButton=true;
				this.$post('parking/finance/refund',this.formData,true,true).then(res=>{
					uni.setStorageSync('refresh',1);
					this.$navigateBack(1500);
				}).catch(err=>{
					this.disabledButton=false;
				});
			},
			
		}
	}
</script>

<style lang="scss" scoped>
.fui-btn__box{
	padding: 20rpx;
}
</style>